package com.li.designpattern.observer;

import java.util.ArrayList;
import java.util.List;

public class Subject {
	private List<Observer> list=new ArrayList<Observer>();
	
	private String state;
	
	public String getState(){
		return state;
	}
	public void setState(String state){
		this.state=state;
		notifyAllObserver();
	}
	
	public void notifyAllObserver(){
		for(Observer observer:list){
			observer.update(state);
		}
	}
	
	public void attach(Observer observer){
		list.add(observer);
	}
}
